//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "logIn.h"
#include "selection.h"
#include "camp.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TcampForm *campForm;
//----------------------------------------------------------------------
class camp{
			  int location;
			  int groupId;

			  public:
			  camp(){location=0; groupId=0;}


			  void setLocation(int locationT){location=locationT;}
			  void setGroupId(int groupIdT){groupId=groupIdT;}

			  int getLocation(){return location;}
			  int getGroupId(){return groupId;}

}c;
class guest{
			int guestId;
			AnsiString name;
			int groupId;
			bool isCamp;

			public:
			guest(){  guestId=0; name=0; groupId=0; isCamp=0; }

			void setGuestId(int guestIdT){guestId=guestIdT;}
			void setName(AnsiString nameT){name=nameT;}
			void setGroupId(int groupIdT){groupId=groupIdT;}
			void setIsCamp(bool isCampT){isCamp=isCampT;}
			int getGuestId(){return guestId;}
			AnsiString getName(){return name;}
			int getGroupId(){return groupId;}
			bool getIsCamp(){return isCamp;}

}g;
//---------------------------------------------------------------------------
__fastcall TcampForm::TcampForm(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------



void __fastcall TcampForm::Button1Click(TObject *Sender)
{
  int id;
  id=this->Edit1->Text.ToInt();

  if(id<11||id>18)
  {
	ShowMessage("The Guest ID input is no valid");
  }

  else
  {
	AnsiString guestId,groupId;
	guestId=this->Edit1->Text;

	this->ADOQuery1->SQL->Clear();
	this->ADOQuery1->SQL->Add("SELECT * FROM guests WHERE guest_id="+guestId);
	this->ADOQuery1->Open();
	g.setGuestId(this->ADOQuery1->FieldByName("guest_id")->AsInteger);
	g.setName(this->ADOQuery1->FieldByName("name")->AsString);
	g.setGroupId(this->ADOQuery1->FieldByName("group_id")->AsInteger);
	g.setIsCamp(this->ADOQuery1->FieldByName("is_camping")->AsInteger) ;
	if(g.getIsCamp()==0)
	{
	   ShowMessage("Not Allowed In Camping");
	}

	else
	{
	   groupId=AnsiString(g.getGroupId());

	   this->ADOQuery1->SQL->Clear();
	   this->ADOQuery1->SQL->Add("SELECT * FROM campsites WHERE group_id="+groupId);
	   this->ADOQuery1->Open();

	   c.setLocation(this->ADOQuery1->FieldByName("location")->AsInteger);

	   this->ADOQuery1->SQL->Clear();
	   this->ADOQuery1->SQL->Add("SELECT * FROM guests WHERE group_id="+groupId);
	   this->ADOQuery1->Open();
	   this->ListBox1->Clear();
	   while(!ADOQuery1->Eof)
	   {
		  g.setName(this->ADOQuery1->FieldByName("name")->AsString);

		  this->ListBox1->Items->Add(g.getName());

		  this->ADOQuery1->Next();
	   }

	   this->Label8->Caption=g.getName();
	   this->Label10->Caption=AnsiString(g.getGroupId());
	   this->Label12->Caption=AnsiString(c.getLocation());

	}
  }


}
//---------------------------------------------------------------------------

void __fastcall TcampForm::Button4Click(TObject *Sender)
{
this->Label8->Caption="";
this->Label10->Caption="";
this->Label12->Caption="";


this->ListBox1->Clear();

}
//---------------------------------------------------------------------------

void __fastcall TcampForm::FormClose(TObject *Sender, TCloseAction &Action)
{
 selectionForm->Close();
 logInForm->Close();
}
//---------------------------------------------------------------------------

void __fastcall TcampForm::Button2Click(TObject *Sender)
{
 this->Visible=false;
 selectionForm->Visible=true;
}
//---------------------------------------------------------------------------

